# -*- encoding=utf8 -*-
"""
RedFlag-TC000025    选择一个4K大于48S的视频，和一个1080P大于48S的视频
先进入相机拍摄大于48S的低/高帧率视频
进入ugc选择视频
"""
__author__ = "ldm"

import sys
import os
# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *
auto_setup(__file__)

shooter = CameraVideoShooter()
log("------------------------------------拍摄视频素材-----------------------")
shooter.local_camera_captures_videos_huaweiP50("30 fps", "720p", 25, open_camera=True, close_camera=False)
shooter.local_camera_captures_videos_huaweiP50("30 fps", "720p", 25, open_camera=False, close_camera=False)
shooter.local_camera_captures_videos_huaweiP50("30 fps", "720p", 48, open_camera=False, close_camera=False)
shooter.local_camera_captures_videos_huaweiP50("60 fps", "4K", 25, open_camera=False, close_camera=False)
shooter.local_camera_captures_videos_huaweiP50("60 fps", "4K", 25, open_camera=False, close_camera=False)
shooter.local_camera_captures_videos_huaweiP50("60 fps", "4K", 48, open_camera=False, close_camera=True)

log("-------------------------场景一：选择两个25S的低帧率视频---------------------")
# 进入相册
shooter.enter_album()
shooter.click_element(album_select_button[4])
shooter.click_element(album_select_button[5])
# 点击下一步
shooter.click_element(album_next_button)
# 等待
shooter.wait_for_element_appearance(poco("cn.migu.video.clip.walle:id/clip_comm_dialog_msg"), 60)
# 点击是
shooter.click_element(tip_to_crop_pop_up_window_correct)
# 点击剪辑
shooter.click_element(edit_button)
# 获取总视频时间文本，这里获取文本不能调用变量，需要直接使用poco
text1 = shooter.get_element_text(poco("cn.migu.video.clip.walle:id/selected_time_tv"))
# 断言
shooter.assert_texts_equal(text1, "00:00 / 00:48", "断言失败，视频总时长与预期时长不符合")
# 关闭应用
stop_app(UGC_package_name)
sleep(5.0)

log("-------------------场景二：选择两个25S的高帧率视频--------------------------------")
# 进入相册
shooter.enter_album()
sleep(1.0)
album_select_button[1].click()
# 断言选择第二个视频选择时是否有高帧率提示
shooter.assert_toast_popup(album_select_button[2], r"tpl1749783398202.png","断言失败，未发现toast弹窗",record_pos=(0.002, -0.007), resolution=(1224, 2700),threshold=0.5)
# 点击下一步
shooter.click_element(album_next_button)
# 等待
shooter.wait_for_element_appearance(poco("cn.migu.video.clip.walle:id/clip_comm_dialog_msg"), 60)
# 点击是
shooter.click_element(tip_to_crop_pop_up_window_correct)
# 点击剪辑
shooter.click_element(edit_button)
# 获取总视频时间文本
text2 = shooter.get_element_text(poco("cn.migu.video.clip.walle:id/selected_time_tv"))
# 断言
shooter.assert_texts_equal(text2, "00:00 / 00:48", "断言失败，视频总时长与预期时长不符合")
# 关闭应用
stop_app(UGC_package_name)
sleep(5.0)

log("-------------------场景三：选择第一个高帧25S，第二个低帧率25S的视频-------------------")
shooter.enter_album()
album_select_button[1].click()
album_select_button[4].click()
# 断言选择第二个视频选择时是否有高帧率提示
shooter.assert_image_not_exists(r"tpl1749783398202.png", "断言失败，目标图片出现")
# 点击下一步
shooter.click_element(album_next_button)
# 等待
shooter.wait_for_element_appearance(poco("cn.migu.video.clip.walle:id/clip_comm_dialog_msg"), 60)
# 点击是
shooter.click_element(tip_to_crop_pop_up_window_correct)
# 点击剪辑
shooter.click_element(edit_button)
# 获取总视频时间文本
text3 = shooter.get_element_text(poco("cn.migu.video.clip.walle:id/selected_time_tv"))
# 断言
shooter.assert_texts_equal(text3, "00:00 / 00:48", "断言失败，视频总时长与预期时长不符合")
# 关闭应用
stop_app(UGC_package_name)
sleep(5.0)

log("-----------------场景四：选择第一个低帧25S，第二个高帧率25S的视频--------------------")
shooter.enter_album()
album_select_button[4].click()
# 断言选择第二个视频选择时是否有高帧率提示
shooter.assert_toast_popup(album_select_button[1], r"tpl1749783398202.png","断言失败，未发现toast弹窗",record_pos=(0.002, -0.007), resolution=(1224, 2700),threshold=0.5, high_freq_interval=0.01)
# 点击下一步
shooter.click_element(album_next_button)
# 等待
shooter.wait_for_element_appearance(poco("cn.migu.video.clip.walle:id/clip_comm_dialog_msg"), 60)
# 点击是
shooter.click_element(tip_to_crop_pop_up_window_correct)
# 点击剪辑
shooter.click_element(edit_button)
# 获取总视频时间文本
text4 = shooter.get_element_text(poco("cn.migu.video.clip.walle:id/selected_time_tv"))
# 断言
shooter.assert_texts_equal(text4, "00:00 / 00:48", "断言失败，视频总时长与预期时长不符合")
# 关闭应用
stop_app(UGC_package_name)
sleep(5.0)

log("-----------------场景五：选择第一个高帧48S，第二个低帧率48S的视频-------------------")
# 进入相册
shooter.enter_album()
shooter.assert_toast_popup(album_select_button[0], r"tpl1749783398202.png","断言失败，未发现toast弹窗",record_pos=(0.002, -0.007), resolution=(1224, 2700),threshold=0.5, high_freq_interval=0.01)
album_select_button[3].click()
# 点击下一步
shooter.click_element(album_next_button)
# 等待
shooter.wait_for_element_appearance(poco("cn.migu.video.clip.walle:id/clip_comm_dialog_msg"), 60)
# 点击是
shooter.click_element(tip_to_crop_pop_up_window_correct)
# 点击剪辑
shooter.click_element(edit_button)
# 获取视频时间文本
duration_text = shooter.get_element_text(edit_total_video_duration)
first_paragraph_text = shooter.get_element_text(edit_total_first_paragraph)
# 断言
shooter.assert_texts_equal(duration_text, "00:00 / 00:48", "断言失败，视频总时长与预期时长不符合") 
shooter.assert_texts_equal(first_paragraph_text, "48.0s", "断言失败，视频总时长与预期时长不符合")

# 关闭应用
stop_app(UGC_package_name)
